package com.bkhech.spring.security.example.service;

import com.bkhech.spring.security.example.contants.SecurityCons;
import com.bkhech.spring.security.example.domain.dao.UserInfo;
import org.springframework.security.access.vote.RoleVoter;
import org.springframework.security.core.userdetails.UserDetailsService;

import java.util.Map;

/**
 * @author guowm
 * @date 2023/1/11
 */
public interface UserService extends UserDetailsService {

    String rolePrefix = getRolePrefix();

    /**
     * $2a$10$SD5QrF6JtVuo/6Y0dR8bVe/VUEDhin25SgRMKTz70VLXY4nixFwFS
     * 123456
     */
    Map<String, UserInfo> users = Map.ofEntries(
            Map.entry("zhangsan", new UserInfo(1L, "zhangsan", "$2a$10$SD5QrF6JtVuo/6Y0dR8bVe/VUEDhin25SgRMKTz70VLXY4nixFwFS", rolePrefix + SecurityCons.roleAdminCode, false, false, true)),
            Map.entry("lisi", new UserInfo(2L, "lisi", "$2a$10$SD5QrF6JtVuo/6Y0dR8bVe/VUEDhin25SgRMKTz70VLXY4nixFwFS", rolePrefix + SecurityCons.roleCommonUserCode, false, false, true))
    );

    static String getRolePrefix() {
//        final SimpleAuthorityMapper simpleAuthorityMapper = new SimpleAuthorityMapper();
        RoleVoter roleVoter = new RoleVoter();
        return roleVoter.getRolePrefix();
    }

    /**
     * 通过用户名查询用户
     *
     * @param username 用户名
     * @return 用户对象信息
     */
    UserInfo getUserByUsername(String username);

    /**
     * 判断密码是否匹配
     *
     * @param rawPassword     未加密的密码
     * @param encodedPassword 加密后的密码
     * @return 是否匹配
     */
    boolean isPasswordMatch(String rawPassword, String encodedPassword);


}
